/*
 * poi数据导出
 * @authorCyoung
 * date 3-15,2012
 */
package com.hz.data;

import java.io.FileOutputStream;
import java.io.IOException;
import java.text.ParseException;
import java.util.Collection;
import java.util.Iterator;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.CellRangeAddress;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.IndexedColors;

import com.hz.control.ParamDepartmentManager;
import com.hz.control.ParamSpecialManage;
import com.hz.model.User;



@SuppressWarnings("deprecation")
public class Export {
	
	
	/*
	 * 导出statics表的数据
    */
	@SuppressWarnings("unchecked")
	public static void ExportUsers(String filename,Collection<User>ulist)throws IOException{
		HSSFWorkbook wb = new HSSFWorkbook();
		HSSFSheet sheet = wb.createSheet("综合数据");
		sheet.setColumnWidth(0, 3800); //設置列寬
		
		
		HSSFCellStyle normalStyle = wb.createCellStyle();
		normalStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
		normalStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
		normalStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
		normalStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
		normalStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
		normalStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
		//normalStyle.setWrapText(true);//是否自動換行
		
		//int colIndex = 1;//控制单元格的位置；
		//int colSize = 0;//控制合并单元格的长度
		
		HSSFRow row = sheet.createRow(0);
		HSSFCell cell = null;
		
		cell = row.createCell(0);
		cell.setCellValue("学号");
		cell.setCellStyle(normalStyle);
		
		cell = row.createCell(1);
		cell.setCellValue("姓名");
		cell.setCellStyle(normalStyle);
		
		cell = row.createCell(2);
		cell.setCellValue("电话");
		cell.setCellStyle(normalStyle);
		
		cell = row.createCell(3);
		cell.setCellValue("QQ");
		cell.setCellStyle(normalStyle);
		
		cell = row.createCell(4);
		cell.setCellValue("学院");
		cell.setCellStyle(normalStyle);
		
		cell = row.createCell(5);
		cell.setCellValue("专业");
		cell.setCellStyle(normalStyle);
		
		cell = row.createCell(6);
		cell.setCellValue("星级");
		cell.setCellStyle(normalStyle);
		
		
		Iterator uit = ulist.iterator();
		int index=1;
		while(uit.hasNext()){
		
		     User u = (User) uit.next(); 
		     row = sheet.createRow(index++);
		
		
		     cell = row.createCell(0);
	             cell.setCellValue(u.getStuNum());
		     cell.setCellStyle(normalStyle);
		
		     cell = row.createCell(1);
		     cell.setCellValue(u.getRealname());
		     cell.setCellStyle(normalStyle);
		
		     cell = row.createCell(2);
		     cell.setCellValue(u.getTel());
		     cell.setCellStyle(normalStyle);
		
		     cell = row.createCell(3);
		     cell.setCellValue(u.getQq());
		     cell.setCellStyle(normalStyle);
		
		     cell = row.createCell(4);
		     cell.setCellValue(ParamDepartmentManager.findDepartment(u.getDepartmentId()).getDepartmentSmallName());
		     cell.setCellStyle(normalStyle);
		
		     cell = row.createCell(5);
		     cell.setCellValue(ParamSpecialManage.getSpecialById(u.getMajorId()).getSpecialName() );
		     cell.setCellStyle(normalStyle);
		
		     cell = row.createCell(6);
		     cell.setCellValue(u.getVolunteerLev());
		     cell.setCellStyle(normalStyle);
	 	}
		FileOutputStream out = new FileOutputStream(filename);
		wb.write(out);
		out.close();
	}
	
	
	
	public static void main(String args[]) throws IOException, ParseException{
		//Export.ExportStatics("D:\\evasystem.xls",2010,1);
		//Export.ExportDetail("D:\\detail.xls",2010,StuyearControl.getStuyearIdByTime(DateControl.Date()));
		//String a ="dddd";
		//System.out.println("\""+a+"\"");
	}
	
	

}
